/**
 * Created by sun on 2015/3/12.
 */
package com.jbm.jbmsupplier.util;

import org.apache.mina.core.filterchain.IoFilterAdapter;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.future.ReadFuture;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.keepalive.KeepAliveFilter;
import org.apache.mina.filter.keepalive.KeepAliveMessageFactory;
import org.apache.mina.filter.keepalive.KeepAliveRequestTimeoutHandler;
import org.apache.mina.transport.socket.SocketSessionConfig;
import org.apache.mina.transport.socket.nio.NioSocketConnector;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class Interface
{
    public Interface ( )
    {
        this.pver = 0;
        this.sver = 3;
        this.build = 12;

        this.islogin = false;
    }

    private NioSocketConnector connector;
    private ConnectFuture cf;
    private IoSession ios;
    private String ip;
    private int port;
    private int timeout;
    public static int BUFFER_LEN = 65536;

    public int pver;
    public int sver;
    public int build;

    public int login_id;
    public int member_id;

    public String account;
    public String pass;
    public  String nickname;
    public String logo;
    public int sex;
     public LoginEntity loginEntity;
    boolean islogin;

    public String Connect ( String ip, int port, int timeout, boolean heartbeat )
    {
        this.ip = ip;
        this.port = port;
        this.timeout = timeout;
        this.connector = new NioSocketConnector();
        this.connector.setConnectTimeoutMillis(timeout);
        this.connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new OHCodeFactory("UTF-8")));
        this.connector.setDefaultRemoteAddress(new InetSocketAddress(ip,port));
        SocketSessionConfig cfg = this.connector.getSessionConfig();
        cfg.setUseReadOperation(true);

        if ( heartbeat )
        {
            //Init HeartBeat
            KeepAliveMessageFactory kamf = new JBMKeepAliveMessageFactory(HBType.CLIENT);
            KeepAliveFilter kaf = new KeepAliveFilter(kamf, IdleStatus.READER_IDLE, KeepAliveRequestTimeoutHandler.CLOSE);
            kaf.setForwardEvent(true);
            kaf.setRequestInterval(10);
            kaf.setRequestTimeout(5);
            this.connector.getFilterChain().addLast("heart", kaf);

            this.connector.setHandler(new MinaClientHandler());

            connector.getFilterChain().addFirst("reconnection", new IoFilterAdapter()
            {
                @Override
                public void sessionClosed(NextFilter nextFilter, IoSession iosession) throws Exception
                {
                    for (; ; )
                    {
                        try
                        {
                            cf = connector.connect();
                            cf.awaitUninterruptibly();// 等待连接创建成功
                            ios = cf.getSession();// 获取会话
                            if (ios.isConnected())
                            {

                                if (islogin)
                                    Login(account, pass);
                                break;
                            }
                        } catch (Exception ex)
                        {

                        }
                        Thread.sleep(3000);
                    }
                }
            });
        }

        this.cf = this.connector.connect ( );
        this.cf.awaitUninterruptibly ( );

        this.ios = this.cf.getSession();

        return "OK";
    }

    public String ConfirmVer ( )
    {
        try
        {
            this.ios.write(new IVersion(pver,sver,build)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                String status = (String) rf.getMessage();
                return status;
            }else
                return "FAILED";
        }catch (Exception e)
        {
            return "FAILED";
        }
    }

    public String Login ( String name, String pass)
    {
        try
        {
            this.ios.write(new  ILogin(name, pass)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                Login rtn = (Login) rf.getMessage();

                if ( rtn.login_id > 0 )
                {
                    this.login_id = rtn.login_id;
                    this.member_id = rtn.member_id;

                    this.account = name;
                    this.pass = pass;
                    this.islogin = true;
                    this.logo=rtn.logo;
                    this.nickname=rtn.nickname;
                    this.sex=rtn.sex;
                    return "Login OK";
                }else
                    return rtn.errorinfo;
            }else
                return "FAILED";
        }catch (Exception e)
        {
            return "FAILED";
        }
    }

    public String ChangePass ( String pass, String oldpass )
    {
        try
        {
            this.ios.write(new ILogin("", pass, oldpass)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                String rtn = (String) rf.getMessage();

                return rtn;
            }else
                return "FAILED";
        }catch (Exception e)
        {
            return "FAILED";
        }
    }
    //重置密码
    public String ResetPass ( String pass, String name )
    {
        try
        {
            ILogin obj=new ILogin(name, pass, "");
            obj.method="resetpass";
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                String rtn = (String) rf.getMessage();

                return rtn;
            }else
                return "FAILED";
        }catch (Exception e)
        {
            return "FAILED";
        }
    }
    //工单列表
    public IJOrderCtrl GetJOrderList ( int order_id, int start, int count)
    {
        try
        {
            this.ios.write(new IJOrder( "getlist", order_id, start, count)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IJOrderCtrl jc = (IJOrderCtrl) rf.getMessage();
                return jc;
            }else
                return new IJOrderCtrl( false, "网络超时");
        }catch (Exception e)
        {
            return new IJOrderCtrl( false,e.getMessage());
        }
    }
    //工单列表
    public IJOrderCtrl GetJOrderList ( String status, int start, int count)
    {
        try
        {
            this.ios.write(new IJOrder( "getlist", status, start, count)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IJOrderCtrl jc = (IJOrderCtrl) rf.getMessage();
                return jc;
            }else
                return new IJOrderCtrl( false, "网络超时");
        }catch (Exception e)
        {
            return new IJOrderCtrl( false, e.getMessage());
        }
    }
    //新加 工单列表
    public IJOrderCtrl GetJOrderListN ( String status, int start, int count)
    {
        try
        {
            this.ios.write(new IJOrder( "getJobList", status, start, count)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IJOrderCtrl jc = (IJOrderCtrl) rf.getMessage();
                return jc;
            }else
                return new IJOrderCtrl( false, "网络超时");
        }catch (Exception e)
        {
            return new IJOrderCtrl( false, e.getMessage());
        }
    }
    //老 工单详细
    public IJOrder LoadJOrder ( int jorder_id )
    {
        try
        {
            this.ios.write(new IJOrder( "load", jorder_id)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IJOrder jorder = (IJOrder) rf.getMessage();
                return jorder;
            }else
                return new IJOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IJOrder( false, e.getMessage());
        }
    }
    //新加 工单详细
    public JobOrderEntity LoadJOrderN ( int jorder_id )
    {
        try
        {
            this.ios.write(new IJOrder( "LoadJOrder", jorder_id)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                JobOrderEntity jorder = (JobOrderEntity) rf.getMessage();
                return jorder;
            }else
                return new JobOrderEntity( false, "网络超时");
        }catch (Exception e)
        {
            return new JobOrderEntity( false,e.getMessage());
        }
    }
    //中止工单
    public IJOrder BreakJob ( int jorder_id, String memo )
    {
        try
        {
            this.ios.write(new IJOrder( "breakjob", jorder_id,memo)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IJOrder jorder = (IJOrder) rf.getMessage();
                return jorder;
            }else
                return new IJOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IJOrder( false, e.getMessage());
        }
    }
    //提交工单
    public IJOrder SubmitJob ( int jorder_id, String amount, String job_sum, String guarantee_date )
    {
        try
        {
            this.ios.write(new IJOrder( "submit", jorder_id, amount, job_sum, guarantee_date )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IJOrder jorder = (IJOrder) rf.getMessage();
                return jorder;
            }else
                return new IJOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IJOrder( false, e.getMessage());
        }
    }

     //提交工单 使用代金券
    public IJOrder SubmitJob ( int jorder_id, String amount, String job_sum, String guarantee_date,int voucher,int voucher_id )
    {
        try
        {
            this.ios.write(new IJOrder( "submit", jorder_id, amount, job_sum, guarantee_date ,voucher,voucher_id)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IJOrder jorder = (IJOrder) rf.getMessage();
                return jorder;
            }else
                return new IJOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IJOrder( false, e.getMessage());
        }
    }
    //确定工单 手机端用
    public IJOrder ConfirmJob ( int jorder_id )
    {
        try
        {
            this.ios.write(new IJOrder( "confirm", jorder_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IJOrder jorder = (IJOrder) rf.getMessage();
                return jorder;
            }else
                return new IJOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IJOrder( false, e.getMessage());
        }
    }

    public IJOrder HoldJob ( int jorder_id )
    {
        try
        {
            this.ios.write(new IJOrder( "hold", jorder_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IJOrder jorder = (IJOrder) rf.getMessage();
                return jorder;
            }else
                return new IJOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IJOrder( false, e.getMessage());
        }
    }

    public IJOrder ContinueJob ( int jorder_id )
    {
        try
        {
            this.ios.write(new IJOrder( "continue", jorder_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IJOrder jorder = (IJOrder) rf.getMessage();
                return jorder;
            }else
                return new IJOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IJOrder( false, e.getMessage());
        }
    }

    public Media UploadMedia ( int folderid, String foldertype, Media media )
    {
        try
        {
            if ( !media.mtype.equals("text") )
            {
                IUploadMedia ium = new IUploadMedia( folderid, foldertype, media );
                ium.buffer = new byte[BUFFER_LEN];

                Media rtn;

                if ( media.mid == 0 && media.offset > 0 )
                {
                    media.offset = -1;
                    return media;
                }
                RandomAccessFile raf = new RandomAccessFile(media.filepath,"r");
                media.filepath = "";
                raf.seek(media.offset);

                int len;
                do
                {
                    len = raf.read(ium.buffer,0,BUFFER_LEN);

                    ium.bufferlen = len==-1?0:len;
                    this.ios.write(ium).awaitUninterruptibly();
                    ReadFuture rf = this.ios.read();
                    if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
                    {
                        rtn = (Media) rf.getMessage();

                        if ( rtn.offset != -1 )
                        {
                            ium.media.offset = rtn.offset;
                            ium.media.mid = rtn.mid;
                            ium.media.filepath = rtn.filepath;
                        }else
                            return rtn;
                    } else
                    {
                        media.offset = -1;
                        return media;
                    }
                }while ( len != -1 );

                raf.close();

                return rtn;
            }else
            {
                this.ios.write(new IUploadMedia(folderid, foldertype, media)).awaitUninterruptibly();
                ReadFuture rf = this.ios.read();
                if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
                {
                    Media rtn = (Media) rf.getMessage();
                    return rtn;
                } else
                {
                    media.offset = -1;
                    return media;
                }
            }
        }catch (Exception e)
        {
            media.offset = -1;
            return media;
        }
    }

    public IDownloadMedia DownloadMedia ( int folderid, String foldertype, Media media )
    {
        IDownloadMedia idm = new IDownloadMedia( folderid, foldertype, media );
        String localpath = media.filepath;
        idm.media.filepath = "";
        RandomAccessFile raf = null;
        try
        {
            if ( !media.mtype.equals("text") )
            {
                IDownloadMedia rtn;

                if ( media.mid <= 0 )
                {
                    idm.media.offset = -1;
                    return idm;
                }

                do
                {
                    this.ios.write(idm).awaitUninterruptibly();
                    ReadFuture rf = this.ios.read();
                    if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
                    {
                        rtn = (IDownloadMedia) rf.getMessage();

                        if ( rtn.media.offset != -1 )
                        {
                            if ( raf == null )
                            {
                                raf = new RandomAccessFile(localpath+rtn.media.filename, "rw");
                                raf.seek(media.offset);
                            }

                            idm.media.offset = rtn.media.offset;
                            idm.media.mid = rtn.media.mid;
                            idm.media.filepath = rtn.media.filepath;
                            idm.media.filename = rtn.media.filename;

                            if ( rtn.bufferlen > 0 )
                                raf.write(rtn.buffer,0,rtn.bufferlen);
                        }else
                        {
                            if ( raf != null )
                                raf.close();;
                            return rtn;
                        }
                    } else
                    {
                        if ( raf != null )
                            raf.close();
                        idm.media.offset = -1;
                        return idm;
                    }
                }while ( rtn.bufferlen > 0 );

                raf.close();

                return rtn;
            }else
            {
                this.ios.write(idm).awaitUninterruptibly();
                ReadFuture rf = this.ios.read();
                if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
                {
                    IDownloadMedia rtn = (IDownloadMedia) rf.getMessage();
                    return rtn;
                } else
                {
                    idm.media.offset = -1;
                    return idm;
                }
            }
        }catch (Exception e)
        {
            idm.media.offset = -1;
            return idm;
        }
    }

    public InputStream InputStreamMedia (int folderid, String foldertype, Media media )
    {
        return new PicInputStream( folderid, foldertype, media, this );
    }

    public IDownloadMedia GetMediaBlock( IDownloadMedia idm )
    {
        IDownloadMedia rtn;
        try
        {
            this.ios.write(idm).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                rtn = (IDownloadMedia) rf.getMessage();
            }else
            {
                rtn = new IDownloadMedia();
                rtn.media.offset = -1;
            }
        }catch (Exception e)
        {
            rtn = new IDownloadMedia();
            rtn.media.offset = -1;
        }

        return rtn;
    }


    public OutputStream OutputStreamMedia (int folderid, String foldertype, Media media )
    {
        if ( media.mid == 0 && media.offset > 0 )
        {
            media.offset = -1;
            return null;
        }

        return new PicOutputStream( folderid, foldertype, media, this );
    }

    public Media PutMediaBlock( IUploadMedia ium )
    {
        Media rtn;
        try
        {
            this.ios.write(ium).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                rtn = (Media) rf.getMessage();
            }else
            {
                rtn = new Media();
                rtn.offset = -1;
            }
        }catch (Exception e)
        {
            rtn = new Media();
            rtn.offset = -1;
        }

        return rtn;
    }

    public Login RegistCustomer ( int login_id, String name, String pass, String repass, String ccode, boolean setsign ,String promotcode)
    {
        Login login;
        try
        {
            this.ios.write(new IRegistCustomer( "reg_new", login_id, name, pass, repass, ccode, setsign,promotcode )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                login = (Login) rf.getMessage();
                if ( login.login_id > 0 )
                {
                    this.login_id = login.login_id;
                    this.member_id = login.member_id;
                    this.islogin = true;
                    this.logo=login.logo;
                    this.nickname=login.nickname;
                    this.sex=login.sex;

                }
            }else
            {
                login = new Login();
                login.login_id = -1;
                login.errorinfo = "网络超时";
            }
        }catch (Exception e)
        {
            login = new Login();
            login.login_id = -1;
            login.errorinfo = e.getMessage();
        }

        return login;
    }

    public Login RegistCustomer ( int login_id, String name, String pass, String repass, String ccode, int vcode_id, String mm_unionid, String nickname, int sex,String logo,String promotcode )
    {
        Login login;
        try
        {
            this.ios.write(new IRegistCustomer( "bind_all", login_id, name, pass, repass, ccode, vcode_id, mm_unionid, nickname, sex ,logo,promotcode)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                login = (Login) rf.getMessage();
                if ( login.login_id > 0 )
                {
                    this.login_id = login.login_id;
                    this.member_id = login.member_id;
                    this.islogin = true;
                    this.logo=login.logo;
                    this.nickname=login.nickname;
                    this.sex=login.sex;

                }
            }else
            {
                login = new Login();
                login.login_id = -1;
                login.errorinfo = "网络超时";
            }
        }catch (Exception e)
        {
            login = new Login();
            login.login_id = -1;
            login.errorinfo = e.getMessage();
        }

        return login;
    }
    //同步微信 头像昵称 性别
    public Login SyncLogo ( int login_id, String nickname, String logo,  int sex)
    {
        Login login;
        try
        {
            this.ios.write(new IRegistCustomer( "synclogo", login_id,  nickname,logo, sex )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                login = (Login) rf.getMessage();
            }else
            {
                login = new Login();
                login.login_id = -1;
                login.errorinfo = "网络超时";
            }
        }catch (Exception e)
        {
            login = new Login();
            login.login_id = -1;
            login.errorinfo = e.getMessage();
        }

        return login;
    }

    public ICertAddress AddMyCAddr (          int gi_id,
                                              String gi_addon,
                                              String gi_text,
                                              String zip_code,
                                              String contacts,
                                              String mobile,
                                              String phone
    )
    {
        ICertAddress iback;
        try
        {
            this.ios.write(new ICertAddress( "create", 0, member_id, gi_id, gi_addon, gi_text, zip_code, contacts, mobile, phone )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ICertAddress) rf.getMessage();

                return iback;
            }else
            {
                return new ICertAddress( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ICertAddress( false,e.getMessage());
        }
    }

    public ICertAddress AddMyFreeFeeCAddr (          int gi_id,
                                              String gi_addon,
                                              String gi_text,
                                              String zip_code,
                                              String contacts,
                                              String mobile,
                                              String phone
    )
    {
        ICertAddress iback;
        try
        {
            this.ios.write(new ICertAddress( "create", 0, member_id, gi_id, gi_addon, gi_text, zip_code, contacts, mobile, phone, "freefee" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ICertAddress) rf.getMessage();

                return iback;
            }else
            {
                return new ICertAddress( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ICertAddress( false, e.getMessage());
        }
    }

    public ICertAddressCtrl GetMyCAddr ( int caddr_id )
    {
        ICertAddressCtrl iback;
        try
        {
            this.ios.write(new ICertAddress( "getlist", caddr_id, member_id, 0, "", "", "", "", "", "" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ICertAddressCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new ICertAddressCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ICertAddressCtrl( false, e.getMessage());
        }
    }

    public ICertAddressCtrl GetCAddrList ( int member_id, int gi_id, String gi_addon, String gi_text, String zip_code, String contacts, String mobile, String phone, String cert_status )
    {
        ICertAddressCtrl iback;
        try
        {
            this.ios.write(new ICertAddress( "getlist", 0, 0, 0, "", "", "", "", "", "", cert_status )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ICertAddressCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new ICertAddressCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ICertAddressCtrl( false, e.getMessage());
        }
    }

    //已确认申请列表 门禁申请
    public ICertAddressCtrl GetConfrimList (  )
    {
        ICertAddressCtrl iback;
        try
        {
            this.ios.write(new ICertAddress( "getconfirmlist", 0, 0, 0, "", "", "", "", "", "" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ICertAddressCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new ICertAddressCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ICertAddressCtrl( false, e.getMessage());
        }
    }

    public ICertAddress FreeFeeConfirm (     int caddr_id,
                                            String gi_text
    )
    {
        ICertAddress iback;
        try
        {
            this.ios.write(new ICertAddress( "ffconfirm", caddr_id, 0, 0, "", gi_text, "", "", "", "" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ICertAddress) rf.getMessage();

                return iback;
            }else
            {
                return new ICertAddress( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ICertAddress( false,e.getMessage());
        }
    }

    public String FreeFeeComplete ( String address )
    {
        try
        {
            this.ios.write(new ICertAddress( "ffcomplete", 0, 0, 0, "", address, "", "", "", "" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (String) rf.getMessage();
            }else
            {
                return "网络超时";
            }
        }catch (Exception e)
        {
            return e.getMessage();
        }
    }

    public ICertAddress RemoveMyCAddr ( int caddr_id, int member_id )
    {
        ICertAddress iback;
        try
        {
            this.ios.write(new ICertAddress( "delete", caddr_id, member_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ICertAddress) rf.getMessage();

                return iback;
            }else
            {
                return new ICertAddress( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ICertAddress( false,e.getMessage());
        }
    }

    public ICertAddress UpdateMyCAddr (     int caddr_id,
                                            int gi_id,
                                              String gi_addon,
                                              String gi_text,
                                              String zip_code,
                                              String contacts,
                                              String mobile,
                                              String phone
    )
    {
        ICertAddress iback;
        try
        {
            this.ios.write(new ICertAddress( "update", caddr_id, member_id, gi_id, gi_addon, gi_text, zip_code, contacts, mobile, phone )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ICertAddress) rf.getMessage();

                return iback;
            }else
            {
                return new ICertAddress( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ICertAddress( false, e.getMessage());
        }
    }
    //手机端 用 issave=ture 暂停 没有sellerid
    public IOrder CreateOrder ( int seller_id, int caddr_id, String item_desc, String type, String goods_code, boolean issave, String ordertime )
    {
        IOrder iback;
        try
        {
            IOrder icall = null;
            if ( !issave ) //新建
                icall = new IOrder( "create", 0, member_id, seller_id, caddr_id, item_desc, type, "", goods_code, 0, 0, "", "" );
            else   //暂停
                icall = new IOrder( "save", 0, member_id, seller_id, caddr_id, item_desc, type, "", goods_code, 0, 0, "", "" );
            icall.ordertime = ordertime;
            this.ios.write(icall).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrder) rf.getMessage();

                return iback;
            }else
            {
                return new IOrder( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }
    //issave=true   暂停
    //管理端用到
    public IOrder CreateOrder ( int seller_id, int caddr_id, String item_desc, String type, String goods_code, boolean issave )
    {
        return CreateOrder( seller_id, caddr_id, item_desc, type, goods_code, issave, "");
    }
    //创建鸡蛋订单
    public IOrder CreateSaleOrder ( int seller_id, int caddr_id, String item_desc, String type, String goods_code, int qty, String amount, int sact_id )
    {
        IOrder iback;
        try
        {
            this.ios.write(new IOrder( "create", member_id, seller_id, caddr_id, item_desc, type, "", goods_code, qty, amount, sact_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrder) rf.getMessage();

                return iback;
            }else
            {
                return new IOrder( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }
    //卖鸡蛋用
    public ISaleActivity LoadSaleActivity ( int sact_id )
    {
        ISaleActivity iback;
        try
        {
            this.ios.write(new ISaleActivity( "load", sact_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ISaleActivity) rf.getMessage();

                return iback;
            }else
            {
                return new ISaleActivity( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ISaleActivity( false, e.getMessage());
        }
    }

    public IOrder MyGuardHelp ( int caddr_id, String item_desc, boolean issave )
    {
        IOrder iback;
        try
        {
            if ( !issave )
                this.ios.write(new IOrder( "create", 0, member_id, 0, caddr_id, item_desc, "guardhelp", "", "pub_ent_guard", 0, 0, "", "" )).awaitUninterruptibly();
            else
                this.ios.write(new IOrder( "save", 0, member_id, 0, caddr_id, item_desc, "guardhelp", "", "pub_ent_guard", 0, 0, "", "" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrder) rf.getMessage();

                return iback;
            }else
            {
                return new IOrder( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }
    //对讲门提交订单
    //微信端用到
    public IOrder MyGuardHelp ( int caddr_id, String item_desc )
    {
        IOrder iback;
        try
        {
            this.ios.write(new IOrder( "create", 0, member_id, 0, caddr_id, item_desc, "guardhelp", "", "pub_ent_guard", 0, 0, "", "" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrder) rf.getMessage();

                return iback;
            }else
            {
                return new IOrder( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }

    public IOrder MyHBHouseHelp ( int caddr_id, String item_desc, String goods_code, boolean issave )
    {
        IOrder iback;
        try
        {
            if ( !issave )
                this.ios.write(new IOrder( "create", 0, member_id, 0, caddr_id, item_desc, "hbhouse", "", goods_code, 0, 0, "", "" )).awaitUninterruptibly();
            else
                this.ios.write(new IOrder( "save", 0, member_id, 0, caddr_id, item_desc, "hbhouse", "", goods_code, 0, 0, "", "" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrder) rf.getMessage();

                return iback;
            }else
            {
                return new IOrder( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }

    //房管局订单
    //房管局用到
    public IOrder MyHBHouseHelp ( int caddr_id, String item_desc, String goods_code )
    {
        IOrder iback;
        try
        {
            this.ios.write(new IOrder( "create", 0, member_id, 0, caddr_id, item_desc, "hbhouse", "", goods_code, 0, 0, "", "" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrder) rf.getMessage();

                return iback;
            }else
            {
                return new IOrder( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }

    public IOrderCtrl GetMyOrder ( int order_id, String status, int start, int count )
    {
        IOrderCtrl iback;
        try
        {
            this.ios.write(new IOrder( "getlist", order_id, member_id, 0, 0, "", "", status, "", start, count, "", "" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrderCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IOrderCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrderCtrl( false,e.getMessage());
        }
    }
    //老订单详细
    public IOrder LoadOrder ( int order_id )
    {
        try
        {
            this.ios.write(new IOrder( "load", order_id)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IOrder order = (IOrder) rf.getMessage();
                return order;
            }else
                return new IOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }
    //新加    订单详细
    public IorderEntity LoadOrderInfo ( int order_id )
    {
        try
        {
            this.ios.write(new IOrder( "loadorder", order_id)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IorderEntity order = (IorderEntity) rf.getMessage();
                return order;
            }else
                return new IorderEntity( false, "网络超时");
        }catch (Exception e)
        {
            return new IorderEntity( false, e.getMessage());
        }
    }
     //作废订单  手机端用
    public IOrder RevokeOrder ( int order_id )
    {
        try
        {
            this.ios.write(new IOrder( "revoke", order_id)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IOrder order = (IOrder) rf.getMessage();
                return order;
            }else
                return new IOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }
    //新加 作废订单  管理端用
    public IOrder ForceRevokeOrder ( int order_id )
    {
        try
        {
            this.ios.write(new IOrder( "forcerevoke", order_id)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IOrder order = (IOrder) rf.getMessage();
                return order;
            }else
                return new IOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }
    //评价 订单
    public IOrder CommentOrder ( int order_id, String desc, int speed_level, int quality_level, int attitude_level )
    {
        try
        {
            this.ios.write(new IOrder( "comment", order_id, desc, speed_level, quality_level, attitude_level )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IOrder order = (IOrder) rf.getMessage();
                return order;
            }else
                return new IOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }
    //分派工单  更换施工队
    public IOrder CreateJobOrder ( int order_id, int seller_id )
    {
        try
        {
            this.ios.write(new IOrder( "createjob", order_id, seller_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IOrder order = (IOrder) rf.getMessage();
                return order;
            }else
                return new IOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }
    //强制更换施工队
    public IOrder ForceJobOrder ( int order_id, int seller_id )
    {
        try
        {
            this.ios.write(new IOrder( "forcejob", order_id, seller_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                IOrder order = (IOrder) rf.getMessage();
                return order;
            }else
                return new IOrder( false, "网络超时");
        }catch (Exception e)
        {
            return new IOrder( false, e.getMessage());
        }
    }
     //老订单列表
    public IOrderCtrl GetOrderList ( String status, String start_date, String end_date, int start, int count )
    {
        IOrderCtrl iback;
        try
        {
            this.ios.write(new IOrder( "getlist", 0, 0, 0, 0, "", "", status, "", start, count, start_date, end_date )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrderCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IOrderCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrderCtrl( false, e.getMessage());
        }
    }
    //新加 全部订单 管理端用
    public IOrderCtrl GetOrderListN ( String status, String start_date, String end_date, int start, int count )
    {
        IOrderCtrl iback;
        try
        {
            this.ios.write(new IOrder( "getalllist", 0, 0, 0, 0, "", "", status, "", start, count, start_date, end_date )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrderCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IOrderCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrderCtrl( false, e.getMessage());
        }
    }
    //老订单列表
    public IOrderCtrl GetMyOrderList ( String status, String start_date, String end_date, int start, int count )
    {
        IOrderCtrl iback;
        try
        {
            this.ios.write(new IOrder( "getmylist", 0, 0, 0, 0, "", "", status, "", start, count, start_date, end_date )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrderCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IOrderCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrderCtrl( false, e.getMessage());
        }
    }
   //新加      我的订单列表
   public IOrderCtrl GetMyOrderListN ( String status, String start_date, String end_date, int start, int count )
   {
       IOrderCtrl iback;
       try
       {
           this.ios.write(new IOrder( "getmyorderlist", 0, 0, 0, 0, "", "", status, "", start, count, start_date, end_date )).awaitUninterruptibly();
           ReadFuture rf = this.ios.read();
           if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
           {
               iback = (IOrderCtrl) rf.getMessage();

               return iback;
           }else
           {
               return new IOrderCtrl( false, "网络超时");
           }
       }catch (Exception e)
       {
           return new IOrderCtrl( false, e.getMessage());
       }
   }
    //老评价列表
    public IOrderCtrl GetComList ( int start, int count )
    {
        IOrderCtrl iback;
        try
        {
            this.ios.write(new IOrder( "getcomlist", start, count )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrderCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IOrderCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrderCtrl( false, e.getMessage());
        }
    }
    //新加 评价列表
    public IOrderCtrl getCommentList ( int start, int count )
    {
        IOrderCtrl iback;
        try
        {
            IOrder order=new IOrder( "getCommentList", 0, 0 );
            order.start=start;
            order.count=count;
            this.ios.write(order).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOrderCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IOrderCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOrderCtrl( false, e.getMessage());
        }
    }
    public IGeoinfoCtrl GetGeoinfo ( int gi_id, int prev_id, String prev_code, String type )
    {
        IGeoinfoCtrl iback;
        try
        {
            this.ios.write(new IGeoinfo( "getlist", gi_id, prev_id, prev_code, type )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IGeoinfoCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IGeoinfoCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IGeoinfoCtrl( false, e.getMessage());
        }
    }

//    public IGeoinfo CreateGeoUnit ( String )

    public IAppVersion GetLastVersion ( String app_code, int major_ver, int minor_ver, int revision_ver, int build )
    {
        IAppVersion iback;
        try
        {
            this.ios.write(new IAppVersion( "confirm", app_code, major_ver, minor_ver, revision_ver, build )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IAppVersion) rf.getMessage();

                return iback;
            }else
            {
                return new IAppVersion( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IAppVersion( false, e.getMessage());
        }
    }

    public ISeller GetMyselfSeller ( )//type in "owner", "normal", "manager"
    {
        ISeller iback;
        try
        {
            this.ios.write(new ISeller( "loadmyself" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ISeller) rf.getMessage();

                return iback;
            }else
            {
                return new ISeller( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ISeller( false, e.getMessage());
        }
    }

    public ISeller LoadSeller ( int seller_id )//type in "owner", "normal", "manager"
    {
        ISeller iback;
        try
        {
            this.ios.write(new ISeller( "load", seller_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ISeller) rf.getMessage();

                return iback;
            }else
            {
                return new ISeller( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ISeller( false, e.getMessage());
        }
    }

    public ISeller EmployeeJoinSeller ( int seller_id, int emp_id, String emp_role )//type in "owner", "normal", "manager"
    {
        ISeller iback;
        try
        {
            this.ios.write(new ISeller( "joinemployee", seller_id, emp_id, emp_role )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ISeller) rf.getMessage();

                return iback;
            }else
            {
                return new ISeller( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ISeller( false,e.getMessage());
        }
    }

    public ISeller SellerRecharge ( int seller_id, String amount )
    {
        ISeller iback;
        try
        {
            this.ios.write(new ISeller( "recharge", seller_id, amount )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ISeller) rf.getMessage();

                return iback;
            }else
            {
                return new ISeller( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ISeller( false, e.getMessage());
        }
    }

    public ISeller CreatePersonalSeller (
            int prev_seller,
            String seller_code,
            String name,
            String phone,
            String mobile,
            String email,
            String QQ,
            String address
    )
    {
        ISeller iback;
        try
        {
            this.ios.write(new ISeller( "createpersonal", prev_seller, 0, seller_code, name,phone,mobile,email,QQ,address,"","","","", 0, 0 )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ISeller) rf.getMessage();

                return iback;
            }else
            {
                return new ISeller( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ISeller( false, e.getMessage());
        }
    }

    public ISellerCtrl GetSellerList ( String type, int start, int count )
    {
        ISellerCtrl iback;
        try
        {
            this.ios.write(new ISeller( "getlist", 0, 0, "", "","","","","","","",type,"","", start, count )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ISellerCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new ISellerCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ISellerCtrl( false, e.getMessage());
        }
    }

    public ISellerCtrl GetSellerListByTypes ( String types, int start, int count )
    {
        ISellerCtrl iback;
        try
        {
            this.ios.write(new ISeller( "getlist", types, start, count )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ISellerCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new ISellerCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ISellerCtrl( false, e.getMessage());
        }
    }

    public IPayCtrl GetMyPay ( String type, int start, int count, String start_date, String end_date )
    {
        IPayCtrl iback;
        try
        {
            this.ios.write(new IPay( "getmylist", 0, 0, "", "","","","","", start, count, start_date, end_date )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IPayCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IPayCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IPayCtrl( false, e.getMessage());
        }
    }

    public IPayCtrl GetSellerPay ( int seller_id, String type, int start, int count, String start_date, String end_date )
    {
        IPayCtrl iback;
        try
        {
            this.ios.write(new IPay( "getlist", 0, seller_id, "seller", "","","","","", start, count, start_date, end_date )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IPayCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IPayCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IPayCtrl( false, e.getMessage());
        }
    }

    public IJobTotal JobTotalList ( int start, int count, String start_date, String end_date )
    {
        IJobTotal iback;
        try
        {
            this.ios.write(new ITotal( "jobtotal", start, count, start_date, end_date )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IJobTotal) rf.getMessage();

                return iback;
            }else
            {
                return new IJobTotal( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IJobTotal( false,e.getMessage());
        }
    }

    public IEGuardKeyCtrl GetMyEGuardKey ( )
    {
        IEGuardKeyCtrl iback;
        try
        {
            this.ios.write(new IEGuardKey( "getmylist", 0, 0, 0, 0, 0, 0, "", "", "", "", "", "", 0, 0, "", "" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IEGuardKeyCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IEGuardKeyCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IEGuardKeyCtrl( false, e.getMessage());
        }
    }

    public IEGuardKey RegistKeyWithIDCard ( int caddr_id, String card_nom, String name, String id_card )
    {
        IEGuardKey iback;
        try
        {
            this.ios.write(new IEGuardKey( "create", caddr_id, card_nom, name, id_card )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IEGuardKey) rf.getMessage();

                return iback;
            }else
            {
                return new IEGuardKey( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IEGuardKey( false, e.getMessage());
        }
    }

    public IEGuardKey ShareEGuardKey ( int egkey_id, int open_total, String open_date, String expire_date, String mobile, String name, String id_card )
    {
        IEGuardKey iback;
        try
        {
            this.ios.write(new IEGuardKey( "create_share", egkey_id, 0, 0, open_total, 0, 0, open_date, expire_date, "", mobile, name, id_card, 0, 0, "", "" )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IEGuardKey) rf.getMessage();

                return iback;
            }else
            {
                return new IEGuardKey( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IEGuardKey( false, e.getMessage());
        }
    }

    public IEGuardKey GetSafeKey ( String mac )
    {
        IEGuardKey iback;
        try
        {
            this.ios.write(new IEGuardKey( "getsafekey", mac )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IEGuardKey) rf.getMessage();

                return iback;
            }else
            {
                return new IEGuardKey( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IEGuardKey( false, e.getMessage());
        }
    }
    public String UploadEGuardLog ( IEGLogCtrl egllist )
    {
        String iback;
        try
        {
            egllist.method = "upload";
            this.ios.write(egllist).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (String) rf.getMessage();

                return iback;
            }else
            {
                return "网络超时";
            }
        }catch (Exception e)
        {
            return e.getMessage();
        }
    }

    public IEGLogCtrl GetMyEGLog ( )
    {
        IEGLogCtrl iback;
        try
        {
            this.ios.write(new IEGLog( "getmylist", 0 )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IEGLogCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IEGLogCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IEGLogCtrl( false, e.getMessage());
        }
    }

    public IVerifyCode CreateVCode ( String vvalue, String vtype )
    {
        IVerifyCode iback;
        try
        {
            this.ios.write(new IVerifyCode( "create", vvalue, vtype )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IVerifyCode) rf.getMessage();

                return iback;
            }else
            {
                return new IVerifyCode( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IVerifyCode( false, e.getMessage());
        }
    }

    public IAPPJudge CreateAPPJudge ( String keyword, String message )
    {
        IAPPJudge iback;
        try
        {
            this.ios.write(new IAPPJudge( "create", login_id, keyword, message )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IAPPJudge) rf.getMessage();

                return iback;
            }else
            {
                return new IAPPJudge( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IAPPJudge( false, e.getMessage());
        }
    }

    public IEGuard CreateEGuard ( int area_id, int vil_id, String village, int unit_id, String unit, String mac, String open_key, String door_no, String bt_no )
    {
        IEGuard iback;
        try
        {
            this.ios.write(new IEGuard( "create", area_id, vil_id, village, unit_id, unit, mac, open_key, door_no, bt_no )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IEGuard) rf.getMessage();

                return iback;
            }else
            {
                return new IEGuard( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IEGuard( false, e.getMessage());
        }
    }

    public IEGuard LoadEGuard ( int eguard_id, int gi_id )
    {
        IEGuard iback;
        try
        {
            this.ios.write(new IEGuard( "load", eguard_id, gi_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IEGuard) rf.getMessage();

                return iback;
            }else
            {
                return new IEGuard( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IEGuard( false, e.getMessage());
        }
    }

    public IEGuard UpdateEGuard ( int eguard_id, int ebt_id, String mac, String bt_no )
    {
        IEGuard iback;
        try
        {
            this.ios.write(new IEGuard( "update", eguard_id, ebt_id, mac, bt_no )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IEGuard) rf.getMessage();

                return iback;
            }else
            {
                return new IEGuard( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IEGuard( false, e.getMessage());
        }
    }
      /*注册及开门情况日统计
      * startdate  可空
      * enddate, 可空
      * start  可空
      * count 可空
      * */
    public IStatCtrl GetStatDayEGuard ( IStatDayEGuard obj )
    {
        obj.method="getlist";
        IStatCtrl iback=null;
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IStatCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IStatCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IStatCtrl( false, e.getMessage());
        }
    }
    /* 开门记录统计
      * startdate   可空
      * enddate, 可空
      * start  可空
      * count 可空
      * */
    public IStatCtrl GetStatEGuardLog ( IStatEGuardLog obj )
    {
        obj.method="getlist";
        IStatCtrl iback=null;
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IStatCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IStatCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IStatCtrl( false,e.getMessage());
        }
    }
    /* 故障门统计*/
    public IStatCtrl GetStatBrokenEGuard ()
    {
        IStatBrokenEGuard obj= new IStatBrokenEGuard( "getlist" ) ;
        IStatCtrl iback=null;
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IStatCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IStatCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IStatCtrl( false,e.getMessage());
        }
    }

    /* 获得天气信息*/
    public IWeatherCtrl GetWeatherInfo ()
    {
        IWeather obj=   new IWeather( "getinfo" ) ;
        IWeatherCtrl iback=null;
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IWeatherCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IWeatherCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IWeatherCtrl( false, e.getMessage());
        }
    }
    /*小区开门状况统计
 * startdate  可空
 * enddate, 可空
 * gi_Id 必填
 * gi_name 必填
 * */
    public IStatCtrl GetVillage ( String startdate,String enddate ,int gi_Id,String gi_name)
    {
        IStatVillage obj=new    IStatVillage("getlist",startdate,enddate, gi_Id,gi_name);
        IStatCtrl iback=null;
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IStatCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IStatCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IStatCtrl( false,e.getMessage());
        }
    }
    /*小区开门状况统计
* startdate  可空
* enddate, 可空
* gi_Id 必填
* gi_name 必填
* */
    public IStatCtrl GetStatVillPerson ( String startdate,String enddate ,int gi_Id)
    {
        IStatVillage obj=new    IStatVillage("getperson",startdate,enddate, gi_Id,"");
        IStatCtrl iback=null;
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IStatCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IStatCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IStatCtrl( false, e.getMessage());
        }

    }

    /* 开门记录统计
     * login_id   必填
      * startdate   可空
      * enddate, 可空
      * start  可空
      * count 可空
      * */
    public IEGLogCtrl GetStatEGuardLogByPerson ( IStatEGuardLog obj )
    {
        obj.method="getpersonlist";
        IEGLogCtrl iback;
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IEGLogCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IEGLogCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IEGLogCtrl( false, e.getMessage());
        }
    }
   /*获得人员列表
      mobile 必填
    */

    public ISecretCtrl getPersonList ( ISecret obj )
    {
        try
        {
            obj.method="getlist";
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (ISecretCtrl) rf.getMessage();
            }else
            {
                return new ISecretCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ISecretCtrl( false, e.getMessage());
        }
    }
   /*发布信息
       typeId,  content,  phoneModule,  status=1,  scopeList  ,attList(attOrgname,picByte,picType)
    */
    public ICtrl AddInfomation (InfomationEntity obj )
    {
        obj.method="AddInfomation";
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }


    /* 获得信息列表
    status 状态  0 草稿 1发布 2待审核 ，默认传null
    type_id 信息分类，见枚举  可传null
    gi_id   当前小区id
    start
     pagesize每页行数
 */
    public IInformationCtrl GetInfoList (Integer status,Integer type_id,int gi_id,int start,int pagesize)
    {
        InfomationEntity obj=new    InfomationEntity(status,type_id,gi_id,start,pagesize);
        obj.method="GetInfoList";
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IInformationCtrl) rf.getMessage();
            }else
            {
                return new IInformationCtrl( false, "网络超时");
            }

        }catch (Exception e)
        {      return new IInformationCtrl( false, e.getMessage());
        }
    }

    /* 获得信息列表
未登录获取全部 没有地址获取全部
*/
    public IInformationCtrl GetInfoList (Integer status,Integer type_id,int start,int pagesize)
    {
        InfomationEntity obj=new    InfomationEntity(status,type_id,start,pagesize);
        obj.method="GetInfoListByLogin";
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IInformationCtrl) rf.getMessage();
            }else
            {
                return new IInformationCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IInformationCtrl( false, e.getMessage());
        }
    }

    /* 获得我的信息列表
  status 状态  0 草稿 1发布 2待审核 3违规退回 ，默认传null
  type_id 信息分类，见枚举  可传null
  start
   pagesize每页行数
*/
    public IInformationCtrl GetMyInfoList (Integer status,Integer type_id,int start,int pagesize)
    {
        InfomationEntity obj=new    InfomationEntity(status,type_id,start,pagesize);
        obj.method="GetMyInfoList";
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IInformationCtrl) rf.getMessage();
            }else
            {
                return new IInformationCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IInformationCtrl( false, e.getMessage());
        }
    }

    /*
审核信息
status（0草稿  2待审 1发布 3违规退回）
*/
    public ICtrl AuditInfomation (InfoAuditLogEntity obj )
    {
        obj.method="AuditInfomation";
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }
    /*
待审核信息列表
*/
    public IInformationCtrl GetAuditInfoList (int start,int pagesize)
    {
        InfomationEntity obj=new    InfomationEntity(2,null,start,pagesize);
        obj.method="GetAuditInfoList";
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IInformationCtrl) rf.getMessage();
            }else
            {
                return new IInformationCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IInformationCtrl( false, e.getMessage());
        }
    }

    //搜索信息
    public IInformationCtrl GetInfoListBySearch (String content,int gi_id, int start,int pagesize)
    {
        InfomationEntity obj=new    InfomationEntity(content,start,pagesize);
        obj.method="GetInfoListBySearch";
        obj.setGiId(gi_id) ;
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IInformationCtrl) rf.getMessage();
            }else
            {
                return new IInformationCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IInformationCtrl( false, e.getMessage());
        }
    }
    //搜索信息 未登录获取全部 没有地址获取全部
    public IInformationCtrl GetInfoListBySearch (String content,  int start,int pagesize)
    {
        InfomationEntity obj=new    InfomationEntity(content,start,pagesize);
        obj.method="GetInfoListByLogin";
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IInformationCtrl) rf.getMessage();
            }else
            {
                return new IInformationCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IInformationCtrl( false, e.getMessage());
        }
    }
    //按关键字查询商家 信息列表
    public IInformationCtrl getBusInfoListBySearch (String key, int start,int pagesize)
    {
        InfomationEntity obj=new    InfomationEntity(key,start,pagesize);
        obj.method="GetBusInfoListBySearch";
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IInformationCtrl) rf.getMessage();
            }else
            {
                return new IInformationCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IInformationCtrl( false, e.getMessage());
        }
    }
    //刷新信息
    public ICtrl RefreshInfo(int infoid)
    {
        InfomationEntity obj=new    InfomationEntity("RefreshInfo",infoid);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }
    //修改信息
    //
    public ICtrl UpdateInfo(int infoid,Integer typeId,String content,String phoneModule,Integer status,List<GeoInfoEntity> scopeList,List<InfoAttachmentEntity> attlist)
    {
        InfomationEntity obj=new    InfomationEntity("UpdateInfo",infoid,typeId,content,phoneModule,status,scopeList,attlist);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }

    /* 获得我的收藏列表
   start
   pagesize每页行数
*/
    public IInformationCtrl GetMyFocusInfoList (int start,int pagesize)
    {
        InfomationEntity obj=new    InfomationEntity(null,null,start,pagesize);
        obj.method="GetMyFocusInfoList";

        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IInformationCtrl) rf.getMessage();
            }else
            {
                return new IInformationCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IInformationCtrl( false, e.getMessage());
        }
    }
    //删除信息
    public ICtrl DelInfo(int infoid)
    {
        InfomationEntity obj=new    InfomationEntity("DelInfo",infoid);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }
    //信息点赞
    // praiseType见枚举 信息类=1
    public ICtrl InfoPraise(int infoid,int loginid,int praiseType)
    {
        PraiseEntity obj=new   PraiseEntity("InfoPraise",infoid,loginid,praiseType);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }
    //收藏
    // praiseType见枚举 信息类=1
    public ICtrl InfoFocus(int infoid,int loginid,int praiseType)
    {
        FocusEntity obj=new   FocusEntity("InfoFocus",infoid,loginid,praiseType);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }
    //取消收藏
    public ICtrl  FocusCancel(int infoid,int loginid,int praiseType)
    {
        FocusEntity obj=new   FocusEntity("FocusCancel",infoid,loginid,praiseType);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }
    /*
    注册商家
  status（0 待审 1发布 2违规退回）
 */
    public ICtrl AddBusiness (BusinessEntity obj )
    {
        obj.method="AddBusiness";
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }
    /*
注册商家
status（0 待审 1发布 2违规退回）
*/
    public ICtrl AddBusiness (String bus_name,String bus_address,String servicestyle,String sellerscope,String filename,byte[] picbytes,int status)
    {
        BusinessEntity obj=new  BusinessEntity("AddBusiness",bus_name,bus_address,servicestyle,sellerscope,filename,picbytes,status);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }
    //待审核商家列表
    public IBusinessCtrl GetAuditBusList ()
    {
        BusinessEntity obj=new    BusinessEntity("GetAuditBusList",0);
        try
        {
            this.ios.write(obj).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IBusinessCtrl) rf.getMessage();
            }else
            {
                return new IBusinessCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IBusinessCtrl( false, e.getMessage());
        }
    }

    /*
 审核商家
status（0 待审 1发布 2违规退回）
*/
    public ICtrl AuditBusiness (BusAuditLogEntity obj )
    {
        obj.method="AuditBusiness";
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }
     //修改商家
    public ICtrl ModBusiness (int bus_id,String bus_name,String bus_address,String servicestyle,String sellerscope,String filename,byte[] picbytes,int status )
    {
        BusinessEntity obj=new  BusinessEntity("ModBusiness",bus_id,bus_name,bus_address,servicestyle,sellerscope,filename,picbytes,status);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }
    //获得商家信息
    public BusinessEntity GetBusInfo(int login_id)
    {
        BusinessEntity iback;
        try
        {
            this.ios.write(new BusinessEntity( "getinfo", login_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (BusinessEntity) rf.getMessage();

                return iback;
            }else
            {
                return new BusinessEntity( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new BusinessEntity( false, e.getMessage());
        }
    }
    // 审核失败商家信息
    public BusinessEntity GetFailBusInfo(int login_id)
    {
        BusinessEntity iback;
        try
        {
            this.ios.write(new BusinessEntity( "GetFailBusInfo", login_id )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (BusinessEntity) rf.getMessage();

                return iback;
            }else
            {
                return new BusinessEntity( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new BusinessEntity( false, e.getMessage());
        }
    }
    //获得地址信息 带价格， 适用于发布热销信息
    public IGeoEntityCtrl GetGeoinfoP ( int gi_id, int prev_id,   String type )
    {
        IGeoEntityCtrl iback;
        try
        {
            this.ios.write(new GeoInfoEntity( "getlist", gi_id, prev_id,   type )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IGeoEntityCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IGeoEntityCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IGeoEntityCtrl( false,e.getMessage());
        }
    }

    //修改个人信息
    public ICtrl ModPerInof(int loginid, String nickname,int sex)
    {
        LoginEntity log=new    LoginEntity("ModPerInof",loginid,nickname,sex);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(log ,iback);
    }
    //更新头像
    public ICtrl UpdateLogo(int loginid, byte[] bytes,String picname)
    {
        LoginEntity log=new    LoginEntity("UpdateLogo",loginid,bytes,picname);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(log ,iback);
    }
    //获得个人信息
    public LoginEntity getLoginInfo(int login_id)
    {
        LoginEntity iback;
        try
        {
            this.ios.write(new LoginEntity( "getinfo", login_id, "",   0 )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (LoginEntity) rf.getMessage();

                return iback;
            }else
            {
                return new LoginEntity( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new LoginEntity( false, e.getMessage());
        }
    }
    //退出登录
    public   ICtrl Logout()
    {
        LoginEntity log=new    LoginEntity("Logout",0,null,null);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(log ,iback);
    }
    //总积分
    public  IpointsCtrl getTotalPoints(int login_id)
    {
        IpointsCtrl iback;
        try
        {
            this.ios.write(new PointsEntity( "getTotalPoints", login_id, null,null ,0,0)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IpointsCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IpointsCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IpointsCtrl( false, e.getMessage());
        }
    }
    //积分明细
    public  IpointsCtrl getPointsList(int login_id,int start,int pagesize)
    {
        IpointsCtrl iback;
        try
        {
            this.ios.write(new PointsEntity( "getPointsList", login_id, null,null,start,pagesize )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IpointsCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IpointsCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IpointsCtrl( false, e.getMessage());
        }
    }
//   添加可兑换产品
     public ICtrl addExProduct(ExProductEntity e)
     {
         e.method="addProduct";
          ICtrl iback=new ICtrl();
         return  (ICtrl)SendMessage(e ,iback);
     }
    //   删除可兑换产品
    public ICtrl delExProduct(int exp_id)
    {
        ExProductEntity e=new ExProductEntity();
        e.method="del";
        e.setExpId(exp_id);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(e ,iback);
    }
    //   修改可兑换产品
    public ICtrl modExProduct(ExProductEntity e)
    {
        e.method="mod";
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(e ,iback);
    }
    //可兑换产品列表
    public  IExChangeCtrl getProductList(int start,int pagesize)
    {
        IExChangeCtrl iback;
        try
        {
            this.ios.write(new ExProductEntity( "getProductList", 0, null,null ,null,null,1,null,start,pagesize)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IExChangeCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IExChangeCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IExChangeCtrl( false, e.getMessage());
        }
    }
    //可兑换产品列表
    public  IExChangeCtrl getProductList(Integer status, int start,int pagesize)
    {
        IExChangeCtrl iback;
        try
        {
            this.ios.write(new ExProductEntity( "getProductList", 0, null,null ,null,null,status,null,start,pagesize)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IExChangeCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IExChangeCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IExChangeCtrl( false, e.getMessage());
        }
    }
    //可对兑换产品详情
    public ExProductEntity getProductInfo(int exp_id)
    {
        ExProductEntity iback;
        try
        {
            this.ios.write(new ExProductEntity( "getProductInfo", exp_id, null,null ,null,null,null,null,0,0)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (ExProductEntity) rf.getMessage();

                return iback;
            }else
            {
                return new ExProductEntity( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ExProductEntity( false, e.getMessage());
        }
    }
    //积分兑换
    // exp_id  可兑换产品id
    // type 见枚举 ExChangeType
    public   ICtrl exChange(int login_id,int exp_id,int type)
    {
        ExchangeEntity log=new    ExchangeEntity("exChange",login_id,exp_id,type);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(log ,iback);
    }

    //我的代金券列表
    //status 1有效  null所有
    public  IExChangeCtrl getProListByLogin(int login_id,Integer status,int start,int pagesize)
    {
        IExChangeCtrl iback;
        try
        {
            this.ios.write(new VoucherEntity( "getProductList", 0,null, login_id,null ,null,null,null,status,start,pagesize)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IExChangeCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IExChangeCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IExChangeCtrl( false, e.getMessage());
        }
    }
    // 代金券详情
    public  VoucherEntity getVoucherInfo(int voucher_id)
    {
        VoucherEntity iback;
        try
        {
            this.ios.write(new VoucherEntity( "voucherInfo", voucher_id,null, null,null ,null,null,null,null,0,0)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (VoucherEntity) rf.getMessage();

                return iback;
            }else
            {
                return new VoucherEntity( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new VoucherEntity( false, e.getMessage());
        }
    }
    // 代金券详情
    public  VoucherEntity getVoucherInfo(String  voucher_code)
    {
        VoucherEntity iback;
        try
        {
            this.ios.write(new VoucherEntity( "voucherInfoByCode", 0,voucher_code, null,null ,null,null,null,null,0,0)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
                if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
                {
                    iback = (VoucherEntity) rf.getMessage();

                return iback;
            }else
            {
                return new VoucherEntity( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new VoucherEntity( false, e.getMessage());
        }
    }
    //点击数记录
    // type见枚举ClickTimesType
    // mainid 信息id 若天气传null
    // 若登录传  login_id 未登录传serialUmber
    public void addClickTimes(Integer login_id,int type,Integer mainid,String serialUmber)
    {
       this.ios.write(new ClickTimesEntity( "add", login_id,type, mainid,serialUmber)).awaitUninterruptibly();

    }

    //修改配置信息x
    public ICtrl modConfig(int type,String value)
    {
         OtherconfigEntity obj=new  OtherconfigEntity("mod",type,value);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj ,iback);
    }

    // 获取配置列表
    public  IOtherConfigCtrl getConfiglist(int type )
    {
        IOtherConfigCtrl iback;
        try
        {
            this.ios.write(new OtherconfigEntity( "getlist", type,null)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (IOtherConfigCtrl) rf.getMessage();

                return iback;
            }else
            {
                return new IOtherConfigCtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new IOtherConfigCtrl( false, e.getMessage());
        }
    }
    //新加 支付宝支付参数
   public  IAplipay  getAplipayOrderInfo(String orderno,double amout,int voucherid){
       try
       {
           this.ios.write(new IAplipay("getAplipayOrderInfo",orderno, amout,voucherid+"="+voucherid)).awaitUninterruptibly();
           ReadFuture rf = this.ios.read();
           if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
           {
              return (IAplipay) rf.getMessage();
           }else
           {
               return new  IAplipay(false,"网络超时");
           }
       }catch (Exception e)
       {
           return new  IAplipay(false,e.getMessage());
       }
   }
    //支付宝异步返回处理
    public  IAplipay checkResult( Map<String, String> params)
    {
        try
        {
            this.ios.write(new IAplipay("CheckResult",params)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IAplipay) rf.getMessage();
            }else
            {
                return new  IAplipay(false,"网络超时");
            }
        }catch (Exception e)
        {
            return new  IAplipay(false,e.getMessage());
        }
    }

    //支付宝提现
    public  IAplipay transferFee(int acc_id,String acc_type,double amount)
    {
        try
        {
            this.ios.write(new IAplipay("TransferFee",acc_id,acc_type,amount)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IAplipay) rf.getMessage();
            }else
            {
                return new  IAplipay(false,"网络超时");
            }
        }catch (Exception e)
        {
            return new  IAplipay(false,e.getMessage());
        }
    }

    //支付宝退款
    public  IAplipay refund(String orderno,String tradeno,double amount)
    {
        try
        {
            this.ios.write(new IAplipay("refund",orderno,tradeno,amount)).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                return (IAplipay) rf.getMessage();
            }else
            {
                return new  IAplipay(false,"网络超时");
            }
        }catch (Exception e)
        {
            return new  IAplipay(false,e.getMessage());
        }
    }
     //新加   线下付款
    public ICtrl payOffLine(int order_id)
    {
        IOrder obj=new  IOrder("payOffLine",order_id);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj,null );
    }
    //新加 管理端登录
    public LoginEntity  loginm(String username,String password)
    {
        LoginEntity iback;
        try
        {
            this.ios.write(new LoginEntity( "loginm", username,password )).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                iback = (LoginEntity) rf.getMessage();
                if(iback.back)
                {
                    this.islogin=true;
                    this.login_id=iback.getLoginId();
                    this.loginEntity=iback;
                }

                return iback;
            }else
            {
                return new LoginEntity( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new LoginEntity( false, e.getMessage());
        }
    }
    //新加  绑定支付宝账号
    public ICtrl bindAlipay(String aliacount)
    {
        CapitalAccEntity obj=new  CapitalAccEntity();
        obj.method="bindAlipay";
        obj.setAliaccount(aliacount);
        ICtrl iback=new ICtrl();
        return  (ICtrl)SendMessage(obj,null );
    }
    public  Object SendMessage(Object t,Object tt)
    {
        ICtrl rt;
        try
        {
            this.ios.write(t).awaitUninterruptibly();
            ReadFuture rf = this.ios.read();
            if (rf.await(this.timeout, TimeUnit.MILLISECONDS))
            {
                rt = (ICtrl) rf.getMessage();
                return rt;
            }else
            {
                return new ICtrl( false, "网络超时");
            }
        }catch (Exception e)
        {
            return new ICtrl( false,e.getMessage());
        }
    }
}
